
//
//  HomeViewController.m
//  afn
//
//  Created by mac on 2018/5/7.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "HomeViewController.h"
#import "HomeView.h"
@interface HomeViewController ()
@property(nonatomic,strong)HomeView *aView;
@property(nonatomic,strong)NSDictionary *dingWeiDic;


@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _aView=[HomeView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(NAV_HEIGHT);
        make.bottom.mas_equalTo(-TAB_BAR_HEIGHT);
    }];
    _aView.tableArr=[NSMutableArray arrayWithCapacity:0];
    _aView.page=@"1";
    _aView.viewController=self;
    [_aView creatView];
    [self getBanner];
    [self getTableData];
    _aView.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        [self->_aView.tableArr removeAllObjects];
        self->_aView.page=@"1";
        [self getBanner];
        [self getTableData];
    }];
}

-(void)getBanner{
    
    [gongju AFNPOSTDataUrl:@"v1/banner/show" andDic:nil andTableView:self.aView.tableView andViewController:self andSuccessBlock:^(id responseObject) {
        self.aView.homeBannerArr=responseObject;
        
        [gongju AFNPOSTDataUrl:@"v1/hairdresser-type/show" andDic:nil andTableView:self.aView.tableView andViewController:self andSuccessBlock:^(id responseObject) {
            
            [self->_aView.tableView.mj_footer endRefreshing];
            [self->_aView.tableView.mj_header endRefreshing];
           
            [self.aView creatHeadView];

        } anderrorBlock:nil];
    } anderrorBlock:nil];
}

-(void)getTableData{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    _dingWeiDic = [defaults objectForKey:@"dingWei"];
    NSDictionary *dic;
//    if (_dingWeiDic) {
//        dic=[NSDictionary dictionaryWithObjectsAndKeys:_aView.page,@"page",[_dingWeiDic objectForKey:@"longitude"],@"lng",[_dingWeiDic objectForKey:@"latitude"],@"lat", nil];
//    }else{
        dic=[NSDictionary dictionaryWithObjectsAndKeys:_aView.page,@"page",@"0",@"lng",@"0",@"lat", nil];
//    }
    
    NSString *url=[NSString stringWithFormat:@"shops/%@",_aView.page];
    [gongju AFNPOSTDataUrl:url andDic:dic andTableView:self.aView.tableView andViewController:self andSuccessBlock:^(id responseObject) {
        [self->_aView.tableView.mj_footer endRefreshing];
        [self->_aView.tableView.mj_header endRefreshing];
        
        [self.aView.tableArr addObjectsFromArray:[responseObject objectForKey:@"shop_list"]];
        [self.aView.tableView reloadData];
        
    } anderrorBlock:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
